import os
import sys
import platform

OS_NAME = platform.system();
env=DefaultEnvironment().Clone()
BIN_DIR=os.environ['BIN_DIR']
LIB_DIR=os.environ['LIB_DIR']

TK_ROOT=os.environ['TK_ROOT'];
IDL_GEN = os.path.join(TK_ROOT, "tools/idl_gen/index.js")
DLL_DEF_GEN = os.path.join(TK_ROOT, "tools/dll_def_gen/index.js")

cmd1 = "node " + IDL_GEN + " idl/idl.json ./"
cmd2 = "node " + DLL_DEF_GEN + " idl/idl.json mvvm_prop_gen.def"

is_error = 0
is_error |= os.system(cmd1);
is_error |= os.system(cmd2);
if is_error != 0:
  print("mvvm_prop_gen.def gen failed!")

files = ['xml_mvvm_prop.c', 'mvvm_prop_gen.c']

EXPORT_DEF=''
if OS_NAME == 'Windows' :
  if os.environ['TOOLS_NAME'] == '' :
    EXPORT_DEF = ' /DEF:"tools/mvvm_prop_gen/mvvm_prop_gen.def" '
  elif os.environ['TOOLS_NAME'] == 'mingw' :
    EXPORT_DEF = ' "tools/mvvm_prop_gen/mvvm_prop_gen.def" '

LINKFLAGS=env['LINKFLAGS'] + EXPORT_DEF
CFLAGS=env['CFLAGS']
CCFLAGS=env['CCFLAGS']
env.SharedLibrary(os.path.join(BIN_DIR, 'mvvm_prop_gen'), files, LINKFLAGS=LINKFLAGS, CFLAGS=CFLAGS, CCFLAGS=CCFLAGS, LIBS=['mvvm'] + env['LIBS'])

LIBS=['mvvm', 'mvvm_prop_gen'] + env['LIBS']
env.Program(os.path.join(BIN_DIR, 'mvvm_prop_gen'), ['main.c'], LIBS=LIBS)
